package at.playbox.server.endpoints;

import java.io.ByteArrayInputStream;

import javax.annotation.Resource;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.BindingType;
import javax.xml.ws.Provider;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.WebServiceProvider;
import javax.xml.ws.http.HTTPBinding;
import javax.xml.ws.http.HTTPException;

import at.playbox.server.businesslogic.ShopService;

@WebServiceProvider
@BindingType(value = HTTPBinding.HTTP_BINDING)
public class GetSongList implements Provider<Source>
{

	@Resource
	protected WebServiceContext wsContext;

	@SuppressWarnings("unchecked")
	public Source invoke(Source source)
	{
		try
		{
			ShopService service = new ShopService();
			String result = service.createXML(service.getAllSongs());
			return new StreamSource(new ByteArrayInputStream(result.getBytes()));
		}
		catch (Exception e)
		{
			e.printStackTrace();
			throw new HTTPException(500);
		}
	}

}
